{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "36ada879",
   "metadata": {},
   "source": [
    "-----------\n",
    "\n",
    "* 时间：2022-10-17  /  week9\n",
    "* 课程：Python语言\n",
    "* 学习记录人：陈泽鑫\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe669581",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 用户输入\n",
    "\n",
    "> 2. 文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "191cecc1",
   "metadata": {},
   "source": [
    "## 1. 用户输入\n",
    "\n",
    "* input 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2e2486fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号admin\n",
      "密码123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统\n",
    "username = input(\"账号\")\n",
    "password = input(\"密码\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "07a6e1a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b7aff113",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号\n",
      "密码\n",
      "账号不存在或密码不正确，请重新输入\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1 增加判断\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号\")\n",
    "password = input(\"密码\")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and password01 == password:\n",
    "    print(\"登录成功~欢迎\"+user01)\n",
    "\n",
    "\n",
    "\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "     print(\"账号不存在或密码不正确，请重新输入\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a5b09cd1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号admin\n",
      "密码123456\n",
      "登录成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ 5分钟 for+range()\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号\")\n",
    "    password = input(\"密码\")\n",
    "# 情景一：账号密码都正确\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登录成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "# 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后一小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确，请重新输入!您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确，请1小时后再来尝试\")\n",
    "   \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7005fcea",
   "metadata": {},
   "source": [
    "## 2. 字符串的格式化输出\n",
    "\n",
    "> 1. 字符串的拼接\n",
    "> 2. 占位符\n",
    "> 3. 格式化输出的方法：format()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bd3d7b8b",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 用户的信息输入（完善信息）\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m昵称：\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      3\u001b[0m region \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m地区：\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      4\u001b[0m job \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m工作：\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32mE:\\2022PYTHON\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mE:\\2022PYTHON\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''--------INFO'''+ name + '''---------\n",
    "地区：'''+ region + ''' \n",
    "工作：'''+ job + ''' \n",
    "年龄：'''+ age + ''' \n",
    "期待薪资：''' + salary \n",
    "# 麻烦，容易出错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfaefcc6",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d684e357",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：lihua\n",
      "地区：shenzhen\n",
      "工作：qianduankaifa\n",
      "年龄：22\n",
      "期待薪资：11k/month\n",
      "--------INFO lihua ---------\n",
      "地区：shenzhen\n",
      "工作：qianduankaifa\n",
      "年龄：22\n",
      "期待薪资：11k/month\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：字符串的拼接\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''--------INFO %s ---------\n",
    "地区：%s\n",
    "工作：%s\n",
    "年龄：%s\n",
    "期待薪资：%s'''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 有序 不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c9ba15a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：lihua\n",
      "地区：shenzhen\n",
      "工作：python\n",
      "年龄：22\n",
      "期待薪资：18k/month\n",
      "--------INFO lihua ---------\n",
      "地区：shenzhen\n",
      "工作：python\n",
      "年龄：22\n",
      "期待薪资：18k/month\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）：format()\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''--------INFO {昵称} ---------\n",
    "地区：{地区}\n",
    "工作：{工作职位}\n",
    "年龄：{年龄}\n",
    "期待薪资：{薪资}''' .format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 不考虑顺序，只考虑一一对应的关系"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3861e00",
   "metadata": {},
   "source": [
    "## 课后作业：第二章P93 前所有项目练习\n",
    "> 1. 第二章P93 前所有项目练习（下周讲）\n",
    "> 2. 购物车项目\n",
    ">> 要求：\n",
    ">> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户\n",
    ">> 2. 让用户输入商品编号进行商品的购买\n",
    ">> 3. 用户选择商品后，检查用户的余额是否够，若够直接扣款，不够则提醒用户\n",
    ">> 4. 用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38aeb491",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
